{{ header }}
{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" id="button-save" form="form-menu" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
      <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
        <button type="button" class="close" data-dismiss="alert">&times;</button>
      </div>
    {% endif %}
    {% if success %}
      <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
        <button type="button" class="close" data-dismiss="alert">&times;</button>
      </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> {{ text_form }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-menu" class="form-horizontal">
        <div class="table-responsive">
          <table id="menu" class="table table-striped table-bordered table-hover">
            <thead>
              <tr>
                <td class="text-left">{{ entry_title }}</td>
                <td class="text-left">{{ entry_link }}</td>
                <td class="text-left">{{ entry_sort_order }}</td>
                <td class="text-right">{{ entry_status }}</td>
                <td></td>
              </tr>
            </thead>
            <tbody>
            {% set menu_row = 0 %}
            {% for item in menu %}
              <tr id="menu-row{{ menu_row }}">
                <td>
                  {% for language in languages %}
                    <div class="input-group">
                      <span class="input-group-addon">
                        <img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" />
                      </span>
                      {% for key, description in item.description %}
                        {% if key == language.language_id %}
                          <input type="text" name="menu[{{ menu_row }}][description][{{ language.language_id }}]" value="{{ description }}" placeholder="{{ entry_title }}" class="form-control" />
                        {% endif %}
                      {% endfor %}
                    </div>
                  {% endfor %}
                </td>
                <td class="text-left"><input type="text" name="menu[{{ menu_row }}][link]" value="{{ item.link }}" placeholder="{{ entry_link }}" class="form-control" /></td>
                <td class="text-left" style="width:20%;"><input type="text" name="menu[{{ menu_row }}][sort_order]" value="{{ item.sort_order }}" placeholder="{{ entry_sort_order }}" class="form-control" /></td>
                <td class="text-left">
                  <select name="menu[{{ menu_row }}][status]" class="form-control">
                    <option value="1" {% if item.status %}selected="selected"{% endif %}>{{ text_enabled }}</option>
                    <option value="0" {% if item.status == false %}selected="selected"{% endif %}>{{ text_disabled }}</option>
                  </select>
                </td>
                <td class="text-center"><button type="button" onclick="$('#menu-row{{ menu_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
              </tr>
              {% set menu_row = menu_row + 1 %}
            {% endfor %}
            </tbody>
            <tfoot>
            <tr>
              <td colspan="4"></td>
              <td class="text-center"><button type="button" onclick="addMenu();" data-toggle="tooltip" title="{{ button_menu_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
            </tr>
            </tfoot>
          </table>
        </div>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  var menu_row = {{ menu_row }};
  function addMenu() {
    html  = '<tr id="menu-row' + menu_row + '">';
    html += ' <td class="text-left" style="width: 20%">';
    {% for language in languages %}
    html += '   <div class="input-group"><span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span> <input type="text" name="menu[' + menu_row + '][description][{{ language.language_id }}]" value="" placeholder="{{ entry_title }}" class="form-control" /> </div>';
    {% endfor %}
    html += ' </td>';
    html += ' <td class="text-left"><input type="text" name="menu[' + menu_row + '][link]" value="" placeholder="{{ entry_link }}" class="form-control" /></td>';
    html += ' <td class="text-left" style="width:20%;"><input type="text" name="menu[' + menu_row + '][sort_order]" value="" placeholder="{{ entry_sort_order }}" class="form-control" /></td>';
    html += ' <td class="text-left"><select name="menu[' + menu_row + '][status]" class="form-control">';
    html += '   <option value="1">{{ text_enabled }}</option>';
    html += '   <option value="0">{{ text_disabled }}</option>';
    html += ' </select></td>';
    html += '  <td class="text-center"><button type="button" onclick="$(\'#menu-row' + menu_row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
    html += '</tr>';
    $('#menu tbody').append(html);
    menu_row++;
  }
</script>
{{ footer }}